package snapex.core.mapper;

import static org.mybatis.dynamic.sql.SqlBuilder.*;
import static snapex.core.mapper.InvoiceDynamicSqlSupport.*;

import java.util.List;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.SqlBuilder;
import org.mybatis.dynamic.sql.delete.DeleteDSL;
import org.mybatis.dynamic.sql.delete.MyBatis3DeleteModelAdapter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.render.RenderingStrategy;
import org.mybatis.dynamic.sql.select.MyBatis3SelectModelAdapter;
import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
import org.mybatis.dynamic.sql.select.SelectDSL;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.MyBatis3UpdateModelAdapter;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import snapex.core.model.Invoice;

@Mapper
public interface InvoiceMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<Invoice> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("InvoiceResult")
    Invoice selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="InvoiceResult", value = {
        @Result(column="invoice_id", property="invoiceId", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="invoice_code", property="invoiceCode", jdbcType=JdbcType.CHAR),
        @Result(column="invoice_number", property="invoiceNumber", jdbcType=JdbcType.CHAR),
        @Result(column="invoice_date", property="invoiceDate", jdbcType=JdbcType.CHAR),
        @Result(column="amount", property="amount", jdbcType=JdbcType.DECIMAL),
        @Result(column="tax_amount", property="taxAmount", jdbcType=JdbcType.DECIMAL),
        @Result(column="check_code", property="checkCode", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_timestamp", property="createTimestamp", jdbcType=JdbcType.TIMESTAMP)
    })
    List<Invoice> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<Long>> countByExample() {
        return SelectDSL.selectWithMapper(this::count, SqlBuilder.count())
                .from(invoice);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default DeleteDSL<MyBatis3DeleteModelAdapter<Integer>> deleteByExample() {
        return DeleteDSL.deleteFromWithMapper(this::delete, invoice);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(String invoiceId_) {
        return DeleteDSL.deleteFromWithMapper(this::delete, invoice)
                .where(invoiceId, isEqualTo(invoiceId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(Invoice record) {
        return insert(SqlBuilder.insert(record)
                .into(invoice)
                .map(invoiceId).toProperty("invoiceId")
                .map(invoiceCode).toProperty("invoiceCode")
                .map(invoiceNumber).toProperty("invoiceNumber")
                .map(invoiceDate).toProperty("invoiceDate")
                .map(amount).toProperty("amount")
                .map(taxAmount).toProperty("taxAmount")
                .map(checkCode).toProperty("checkCode")
                .map(createTimestamp).toProperty("createTimestamp")
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(Invoice record) {
        return insert(SqlBuilder.insert(record)
                .into(invoice)
                .map(invoiceId).toPropertyWhenPresent("invoiceId", record::getInvoiceId)
                .map(invoiceCode).toPropertyWhenPresent("invoiceCode", record::getInvoiceCode)
                .map(invoiceNumber).toPropertyWhenPresent("invoiceNumber", record::getInvoiceNumber)
                .map(invoiceDate).toPropertyWhenPresent("invoiceDate", record::getInvoiceDate)
                .map(amount).toPropertyWhenPresent("amount", record::getAmount)
                .map(taxAmount).toPropertyWhenPresent("taxAmount", record::getTaxAmount)
                .map(checkCode).toPropertyWhenPresent("checkCode", record::getCheckCode)
                .map(createTimestamp).toPropertyWhenPresent("createTimestamp", record::getCreateTimestamp)
                .build()
                .render(RenderingStrategy.MYBATIS3));
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<Invoice>>> selectByExample() {
        return SelectDSL.selectWithMapper(this::selectMany, invoiceId, invoiceCode, invoiceNumber, invoiceDate, amount, taxAmount, checkCode, createTimestamp)
                .from(invoice);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default QueryExpressionDSL<MyBatis3SelectModelAdapter<List<Invoice>>> selectDistinctByExample() {
        return SelectDSL.selectDistinctWithMapper(this::selectMany, invoiceId, invoiceCode, invoiceNumber, invoiceDate, amount, taxAmount, checkCode, createTimestamp)
                .from(invoice);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Invoice selectByPrimaryKey(String invoiceId_) {
        return SelectDSL.selectWithMapper(this::selectOne, invoiceId, invoiceCode, invoiceNumber, invoiceDate, amount, taxAmount, checkCode, createTimestamp)
                .from(invoice)
                .where(invoiceId, isEqualTo(invoiceId_))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExample(Invoice record) {
        return UpdateDSL.updateWithMapper(this::update, invoice)
                .set(invoiceId).equalTo(record::getInvoiceId)
                .set(invoiceCode).equalTo(record::getInvoiceCode)
                .set(invoiceNumber).equalTo(record::getInvoiceNumber)
                .set(invoiceDate).equalTo(record::getInvoiceDate)
                .set(amount).equalTo(record::getAmount)
                .set(taxAmount).equalTo(record::getTaxAmount)
                .set(checkCode).equalTo(record::getCheckCode)
                .set(createTimestamp).equalTo(record::getCreateTimestamp);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default UpdateDSL<MyBatis3UpdateModelAdapter<Integer>> updateByExampleSelective(Invoice record) {
        return UpdateDSL.updateWithMapper(this::update, invoice)
                .set(invoiceId).equalToWhenPresent(record::getInvoiceId)
                .set(invoiceCode).equalToWhenPresent(record::getInvoiceCode)
                .set(invoiceNumber).equalToWhenPresent(record::getInvoiceNumber)
                .set(invoiceDate).equalToWhenPresent(record::getInvoiceDate)
                .set(amount).equalToWhenPresent(record::getAmount)
                .set(taxAmount).equalToWhenPresent(record::getTaxAmount)
                .set(checkCode).equalToWhenPresent(record::getCheckCode)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(Invoice record) {
        return UpdateDSL.updateWithMapper(this::update, invoice)
                .set(invoiceCode).equalTo(record::getInvoiceCode)
                .set(invoiceNumber).equalTo(record::getInvoiceNumber)
                .set(invoiceDate).equalTo(record::getInvoiceDate)
                .set(amount).equalTo(record::getAmount)
                .set(taxAmount).equalTo(record::getTaxAmount)
                .set(checkCode).equalTo(record::getCheckCode)
                .set(createTimestamp).equalTo(record::getCreateTimestamp)
                .where(invoiceId, isEqualTo(record::getInvoiceId))
                .build()
                .execute();
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(Invoice record) {
        return UpdateDSL.updateWithMapper(this::update, invoice)
                .set(invoiceCode).equalToWhenPresent(record::getInvoiceCode)
                .set(invoiceNumber).equalToWhenPresent(record::getInvoiceNumber)
                .set(invoiceDate).equalToWhenPresent(record::getInvoiceDate)
                .set(amount).equalToWhenPresent(record::getAmount)
                .set(taxAmount).equalToWhenPresent(record::getTaxAmount)
                .set(checkCode).equalToWhenPresent(record::getCheckCode)
                .set(createTimestamp).equalToWhenPresent(record::getCreateTimestamp)
                .where(invoiceId, isEqualTo(record::getInvoiceId))
                .build()
                .execute();
    }
}